#include <iostream>
#include <jsoncpp/json/json.h>

// kv结构 {a:120,b:"123"}
int main()
{
    Json::Value part;
    part["haha"] = "haha";
    part["hehe"] = "hehe";

    Json::Value root;
    root["part"] = part; //注意套娃
    root["x"] = 100;
    root["y"] = 200;
    root["op"] = '+';
    root["desc"] = "this is a + oper";
    Json::FastWriter w;
    //Json::StyledWriter w;
    std::string res = w.write(root); // 序列化
    std::cout << res << std::endl;


    //反序列化
    Json::Reader r;
	Json::Value v;	
    r.parse(res,v);
    int x = v["x"].asInt();
    int y = v["y"].asInt();
    char op = v["op"].asInt();
    std::string desc = v["desc"].asString();
    
    Json::Value temp = v["part"];
    std::cout<<temp["haha"].asString()<<std::endl;
    std::cout<<temp["hehe"].asString()<<std::endl;

    std::cout<<x<<std::endl;
    std::cout<<y<<std::endl;
    std::cout<<op<<std::endl;
    std::cout<<desc<<std::endl;
    return 0;
}
